//   
//   TimeLineCellTableViewCell.swift
//   BaseComponetKit
//   Created  by monkey on 2024/4/7
//   
//   
   
import UIKit

class TimeLineCell: UITableViewCell {
    
    private let titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.boldSystemFont(ofSize: 18)
        label.numberOfLines = 0
        return label
    }()
    
    private let detailLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.numberOfLines = 2
        return label
    }()
    
    private let timeLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textAlignment = .right
        return label
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(titleLabel)
        contentView.addSubview(detailLabel)
        contentView.addSubview(timeLabel)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let padding: CGFloat = 10
        let labelWidth = contentView.bounds.width - padding * 3
        
        titleLabel.frame = CGRect(x: padding, y: padding, width: labelWidth, height: titleLabel.bounds.height)
        detailLabel.frame = CGRect(x: padding, y: titleLabel.frame.maxY + 5, width: labelWidth, height: detailLabel.bounds.height)
        timeLabel.frame = CGRect(x: contentView.bounds.width - labelWidth - padding, y: padding, width: labelWidth, height: timeLabel.bounds.height)
    }
    
    func configure(title: String, detail: String, time: String) {
        titleLabel.text = title
        detailLabel.text = detail
        timeLabel.text = time
        setNeedsLayout()
    }
}

//// Usage in UITableView:
//class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
//    
//    private let tableView: UITableView = {
//        let tableView = UITableView(frame: .zero, style: .plain)
//        tableView.register(TimeLineCell.self, forCellReuseIdentifier: "TimeLineCell")
//        return tableView
//    }()
//    
//    private var timeLineData: [(title: String, detail: String, time: String)] = []
//    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        view.addSubview(tableView)
//        tableView.delegate = self
//        tableView.dataSource = self
//    }
//    
//    override func viewDidLayoutSubviews() {
//        super.viewDidLayoutSubviews()
//        tableView.frame = view.bounds
//    }
//    
//    // MARK: - UITableViewDataSource
//    
//    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        return timeLineData.count
//    }
//    
//    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//        let cell = tableView.dequeueReusableCell(withIdentifier: "TimeLineCell", for: indexPath) as! TimeLineCell
//        let data = timeLineData[indexPath.row]
//        cell.configure(title: data.title, detail: data.detail, time: data.time)
//        return cell
//    }
//    
//    // MARK: - UITableViewDelegate
//    
//    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        return 120 // Set your desired height here
//    }
//}
